package com.bluesky.controller;

import com.bluesky.comm.BusinessExceptionUtils;
import com.bluesky.comm.Result;
import com.bluesky.comm.ResultUtils;
import com.bluesky.dto.lesson024.UserAddRequest;
import com.bluesky.log.OperLog;
import com.bluesky.service.lesson024.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/lesson024")
@Slf4j
public class Lesson024Controller {

    @Autowired
    private IUserService userService;

    @PostMapping("/add")
    @OperLog(log = "用户管理-新增用户")
    public Result<String> add(@Validated @RequestBody UserAddRequest req) {
        return ResultUtils.success(this.userService.add(req));
    }

    @PostMapping("/delete")
    @OperLog(log = "用户管理-删除用户")
    public Result<Boolean> delete(@RequestParam("userId") String userId) {
        //这里抛个异常，演示错误请求
        throw BusinessExceptionUtils.businessException("无权操作");
    }
}
